import java.util.Scanner;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2021-10-07
 * Time: 21:27
 */
public class DelOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        if (bookList.getSize() == 0) {
            System.out.println("书库无书，无法进行删除操作");
            return;
        }
        Scanner reader = new Scanner(System.in);
        String name;
        System.out.print("请输入你要删除的书名：");
        name = reader.nextLine();
        for (int i = 0; i < bookList.getSize(); i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                while (bookList.getSize() - i - 1 != 0) {
                    bookList.setBooks(i, bookList.getBook(i + 1));
                    i++;
                }
                bookList.setSize(bookList.getSize() - 1);
                System.out.println("书籍删除成功！");
                return;
            }
        }
        System.out.println("书库无该图书，无法进行删除操作");
    }
}



